{extend name="../../base/view/common/base" /}
{block name="body"}
<form class="layui-form p-4">
    <h3 class="pb-3">增项资质</h3>
    {if condition="($id == 0)"}
    <table class="layui-table layui-table-form" id="fenpei_box">
        <tr>
            <td colspan="6"><strong>资质信息</strong></td>
        </tr>
        <tr class="layui-form-item check-cret">
            <td class="layui-td-gray">请选择资质</td>
            <td class="layui-inline">
                <select name="" class="cert_from_type" lay-reqText="请选择合同类别">
                    <option value="">请选择资质类别</option>
                    <option value="施工">施工</option>
                    <option value="监理">监理</option>
                    <option value="设计">设计</option>
                    <option value="房地产">房地产</option>
                    <option value="造价">造价</option>
                    <option value="承装修试">承装修试</option>
                </select>
            </td>
            <td class="layui-inline">
                <select name="" class="cert_serial" id="cert_serial"  lay-search
                        lay-filter="cert_serial">
                    <option value="">资质大类</option>
                </select>
            </td>
            <td class="layui-inline">
                <select name="" class="cert_from"  lay-search lay-filter="cert_from">
                    <option value="">资质二类</option>
                </select>
            </td>
            <td class="layui-inline">
                <select name="" class="cert_level" lay-search>
                    <option value="">级别</option>
                </select>
            </td>

            <td class="layui-inline">
                <input type="button" value="保存资质+"
                       class="layui-input save-cert">
            </td>
        </tr>
        <tr class="layui-form-item">
            <td class="layui-td-gray">申报类型</td>
            <td class="layui-inline">
                <select name="is_zx" lay-reqText="请选择申报类型">
                    <option value="">请选择申报类型</option>
                    <option value="新办">新办</option>
                    <option value="增项">增项</option>
                    <option value="现有资质">现有资质</option>
                </select>
            </td>
        </tr>

        <tr class="layui-form-item">
            <td class="layui-td-gray">资质有效期</td>
            <td class="layui-inline">
                <input type="text" id="cert_valid_date" name="cert_valid_date" autocomplete="off"
                       lay-reqText="资质有效期" placeholder="资质有效期" class="layui-input">
            </td>
        </tr>
        <tr class="layui-form-item">

            <td class="layui-td-gray">安全有效期</td>
            <td class="layui-inline">
                <input type="text" id="safety_valid_date" name="safety_valid_date" autocomplete="off"
                       lay-reqText="安全有效期" placeholder="安全有效期" class="layui-input">
            </td>
        </tr>
    </table>
    {else/}
    <table class="layui-table layui-table-form" id="fenpei_box">
        {notempty name="$detail.cert_cates"}
        {volist name="$detail.cert_cates" id="vo"}
        <tr>
            <td>{$vo.cert_serial}</td>
            <td>{$vo.cert_from}</td>
            <td>{$vo.cert_level}</td>
            <td>{$vo.cert_from_type}</td>
            <input name="check_crets[]" type="hidden"
                   value="{$vo.cert_serial}-{$vo.cert_from}-{$vo.cert_level}-{$vo.cert_from_type}">
            <td class="layui-inline">
                <input type="button" value="删除+"
                       class="layui-input del-cert">
            </td>
        </tr>

        {/volist}
        {/notempty}
        <tr>
            <td colspan="6"><strong>资质信息</strong></td>
        </tr>
        <tr class="layui-form-item check-cret">
            <td class="layui-td-gray">请选择资质</td>
            <td class="layui-inline">
                <select name="" class="cert_from_type" lay-reqText="请选择资质类别">
                    <option value="">请选择资质类别</option>
                    <option value="施工">施工</option>
                    <option value="监理">监理</option>
                    <option value="设计">设计</option>
                    <option value="房地产">房地产</option>
                    <option value="造价">造价</option>
                    <option value="承装修试">承装修试</option>
                </select>
            </td>
            <td class="layui-inline">
                <select name="" class="cert_serial"  lay-search lay-filter="cert_serial">
                    <option value="">资质大类</option>
                </select>
            </td>
            <td class="layui-inline">
                <select name="" class="cert_from"  lay-search lay-filter="cert_from">
                    <option value="">资质二类</option>
                </select>
            </td>
            <td class="layui-inline">
                <select name="" class="cert_level"  lay-search>
                    <option value="">级别</option>
                </select>
            </td>

            <td class="layui-inline">
                <input type="button" value="保存资质+"
                       class="layui-input save-cert">
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">申报类型</td>
            <td>
                <select name="is_zx" lay-reqText="请选择申报类型">
                    <option value=""
                    <?php if($detail['is_zx'] == '') echo 'selected' ?>>请选择申报类型</option>
                    <option value="新办"
                    <?php if($detail['is_zx'] == '新办') echo 'selected' ?>>新办</option>
                    <option value="增项"
                    <?php if($detail['is_zx'] == '增项') echo 'selected' ?>>增项</option>
                    <option value="现有资质"
                    <?php if($detail['is_zx'] == '现有资质') echo 'selected' ?>>现有资质</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">资质有效期</td>
            <td>
                <input type="text" id="cert_valid_date" value="{$detail.cert_valid_date}" name="cert_valid_date"
                       autocomplete="off"
                       lay-reqText="资质有效期" placeholder="资质有效期" class="layui-input">
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">安全有效期</td>
            <td>
                <input type="text" id="safety_valid_date" value="{$detail.safety_valid_date}" name="safety_valid_date"
                       autocomplete="off"
                       lay-reqText="安全有效期" placeholder="安全有效期" class="layui-input">
            </td>
        </tr>
    </table>
    {/if}
    <div style="padding: 10px 0">
        <input type="hidden" name="id" value="{$id}"/>
        <input type="hidden" name="license_id" value="{$license_id}"/>
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool', 'tinymce', 'employeepicker'];

    function gouguInit() {
        var form = layui.form, tool = layui.tool, laydate = layui.laydate, employeepicker = layui.employeepicker;

        //编辑器初始化
        var editor = layui.tinymce;
        var edit = editor.render({
            selector: "#container",
            images_upload_url: '/api/index/upload/sourse/tinymce',//图片上传接口
            height: 500
        });

        laydate.render({
            elem: '#cert_valid_date',
            showBottom: false
        });
        laydate.render({
            elem: '#safety_valid_date',
            showBottom: false
        });


        //监听提交
        form.on('submit(webform)', function (data) {

            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    tool.sideClose(1000);
                }
            }
            tool.post("/license/index/archive_add", data.field, callback);
            return false;
        });
        // .empty().parent().remove();
        $('.del-cert').on('click', function () {
            $(this).parent().siblings().remove();
            $(this).parent().remove();
            $(this).remove();
        });
        //监听行工具事件
        $('.save-cert').on('click', function () {
            var cert_serial = $('.cert_serial').val();
            var cert_from = $('.cert_from').val();
            var cert_level = $('.cert_level').val();
            var cert_from_type = $('.cert_from_type').val();
            if (!cert_serial || !cert_from || !cert_level || !cert_from_type) {
                layer.msg('缺少必填项');
                return false;
            }
            var fenpei_box = '<tr class="layui-form-item">';
            fenpei_box += '<td  >' + cert_serial + '</td>';
            fenpei_box += '<td  >' + cert_from + '</td>';
            fenpei_box += '<td  >' + cert_level + '</td>';
            fenpei_box += '<td  >' + cert_from_type + '</td>';
            fenpei_box += '<input name="check_crets[]"  type="hidden" value="' + cert_serial + '|' + cert_from + '|' + cert_level + '|' + cert_from_type + '">';
            fenpei_box += '<td class="layui-inline">';
            fenpei_box += '<input type="button" value="删除+" class="layui-input del-cert">';
            fenpei_box += '</td>';
            fenpei_box += '</tr>';
            $("#fenpei_box").prepend(fenpei_box);
            $('.del-cert').on('click', function () {
                $(this).parent().siblings().remove();
                $(this).parent().remove();
                $(this).remove();
            });
        });

        var cert_serial = $(".cert_serial");
        var CretList = [
            {
                name: '施工总承包', oneList: [
                    {name: '建筑工程', twoList: ["特级", "一级", "二级", "三级"]},
                    {name: '公路工程', twoList: ["二级"]},
                    {name: '铁路工程', twoList: ["特级", "一级", "二级", "三级"]},
                    {name: '港口与航道工程', twoList: ["特级", "一级", "二级"]},
                    {name: '水利水电工程', twoList: ["二级"]},
                    {name: '市政公用工程', twoList: ["特级", "一级", "二级", "三级"]},
                    {name: '电力工程', twoList: ["特级", "一级", "二级", "三级"]},
                    {name: '矿山工程', twoList: ["特级", "一级", "二级"]},
                    {name: '治金工程', twoList: ["特级", "一级", "二级", "三级"]},
                    {name: '石油化工工程', twoList: ["特级", "一级", "二级", "三级"]},
                    {name: '通信工程', twoList: ["二级", "三级"]},
                    {name: '机电工程', twoList: ["一级", "二级", "三级"]}
                ]
            },
            {
                name: '专业承包', oneList: [
                    {name: '钢结构工程', twoList: ["一级", "二级", "三级"]},
                    {name: '地基基础工程', twoList: ["二级","三级"]},
                    {name: '起重设备安装工程', twoList: ["一级", "二级", "三级"]},
                    {name: '预拌混疑士', twoList: ["不分等级"]},
                    {name: '电子与智能化工程', twoList: ["二级"]},
                    {name: '消防设施工程', twoList: ["一级", "二级"]},//
                    {name: '防水防腐保温工程', twoList: ["一级", "二级"]},
                    {name: '桥梁工程', twoList: ["一级", "二级", "三级"]},
                    {name: '隧道工程', twoList: ["一级", "二级", "三级"]},
                    {name: '模板脚手架', twoList: ["不分等级"]},
                    {name: '建筑装修装饰工程', twoList: ["一级", "二级"]},
                    {name: '建筑机电安装工程', twoList: ["一级", "二级", "三级"]},
                    {name: '建筑幕墙工程', twoList: ["一级", "二级"]},
                    {name: '古建筑工程', twoList: ["一级", "二级", "三级"]},
                    {name: '城市及道路照明工程', twoList: ["一级", "二级", "三级"]},
                    {name: '公路路面工程', twoList: ["二级", "三级"]},
                    {name: '公路路基工程', twoList: ["一级", "二级", "三级"]},
                    {name: '公路交通工程', twoList: ["公路机电工程分项一级", "公路机电工程分项二级", "公路交通安全设施一级", "公路交通安全设施二级"]},
                    {name: '铁路电务工程', twoList: ["一级", "二级", "三级"]},
                    {name: '铁路铺轨架梁工程', twoList: ["一级", "二级"]},
                    {name: '铁路电气化工程', twoList: ["一级", "二级", "三级"]},
                    {name: '机场场道工程', twoList: ["一级", "二级"]},
                    {name: '民航空管工程及机场弱电系统工程', twoList: ["一级", "二级"]},
                    {name: '机场目视助航工程', twoList: ["一级", "二级"]},
                    {name: '港口与海岸工程', twoList: ["一级", "二级", "三级"]},
                    {name: '航道工程', twoList: ["一级", "二级", "三级"]},
                    {name: '通航建筑物工程', twoList: ["一级", "二级", "三级"]},
                    {name: '港航设备安装及水上交管工程', twoList: ["一级", "二级"]},
                    {name: '水工金属结构制作与安装工程', twoList: ["一级", "二级", "三级"]},
                    {name: '水利水电机电安装工程', twoList: ["一级", "二级", "三级"]},
                    {name: '河湖整治工程', twoList: ["一级", "二级", "三级"]},
                    {name: '输变电工程', twoList: ["一级", "二级", "三级"]},
                    {name: '核工程', twoList: ["一级", "二级"]},
                    {name: '海洋石油工程', twoList: ["一级", "二级"]},
                    {name: '环保工程', twoList: ["一级", "二级", "三级"]},
                    {name: '特种工程', twoList: ["不分等级"]},
                ]
            }, {
                name: '施工劳务', oneList: [
                    {name: '施工劳务（备案）', twoList: ["不分等级"]},
                    {name: '施工劳务', twoList: ["不分等级"]}
                ]
            },
            {
                name: '工程设计综合资质', oneList: [
                    {name: '工程设计综合资质', twoList: ["甲级"]}
                ]
            },
            {
                name: '行业资质', oneList: [
                    {name: '煤炭行业', twoList: ["甲级", "乙级"]},
                    {name: '化工石化医药行业', twoList: ["甲级", "乙级"]},
                    {name: '石油天然气(海洋石油)行业', twoList: ["不分等级"]},
                    {name: '电力行业', twoList: ["甲级", "乙级"]},
                    {name: '冶金行业', twoList: ["甲级", "乙级"]},
                    {name: '军工行业', twoList: ["甲级", "乙级"]},
                    {name: '机械行业', twoList: ["甲级", "乙级"]},
                    {name: '商物粮行业', twoList: ["甲级", "乙级"]},
                    {name: '核工业行业', twoList: ["甲级"]},
                    {name: '广电工程', twoList: ["甲级", "乙级"]},
                    {name: '电子工程', twoList: ["甲级"]},
                    {name: '电子通信广电行业', twoList: ["不分等级"]},
                    {name: '轻纺行业', twoList: ["不分等级"]},
                    {name: '建材行业', twoList: ["甲级", "乙级"]},
                    {name: '铁道行业', twoList: ["乙级"]},
                    {name: '公路行业', twoList: ["甲级"]},
                    {name: '水运行业', twoList: ["乙级"]},
                    {name: '民航行业', twoList: ["甲级", "乙级"]},
                    {name: '市政行业', twoList: ["甲级", "乙级"]},
                    {name: '市政(燃气工程、轨道交通工程除外)', twoList: ["甲级", "乙级"]}
                ]
            }, {
                name: '专业资质-军工行业', oneList: [
                    {name: '导释及火筋弹工程', twoList: ["甲级", "乙级"]},
                    {name: '弹、火工品及固体发动机工程', twoList: ["甲级", "乙级"]},
                    {name: '燃机、动力装置及航天发动机工程', twoList: ["甲级", "乙级"]},
                    {name: '科研、靶场、试验，教育培训工程', twoList: ["甲级", "乙级"]},
                    {name: '地而设备工程', twoList: ["甲级", "乙级"]},
                    {name: '航大空间飞行器工程', twoList: ["甲级", "乙级"]},
                    {name: '运载火箭制造工程', twoList: ["甲级", "乙级"]},
                    {name: '地面制导站工程', twoList: ["甲级", "乙级"]},
                ]
            }, {
                name: '专业资质-机械行业', oneList: [
                    {name: '通用设备制造业工程', twoList: ["甲级", "乙级"]},
                    {name: '专用设备制造业工程', twoList: ["甲级", "乙级"]},
                    {name: '交通运输设备制造业工程', twoList: ["甲级", "乙级"]},
                    {name: '电气机械设备制造业工程', twoList: ["甲级", "乙级"]},
                    {name: '全属制品业工程', twoList: ["甲级", "乙级"]},
                    {name: '仪器仪表及文化办公机械制适业工程', twoList: ["甲级", "乙级"]},
                    {name: '机械加工', twoList: ["甲级", "乙级"]},
                    {name: '热加工', twoList: ["甲级", "乙级"]},
                    {name: '交通运输设备制造业工程', twoList: ["甲级", "乙级"]},
                    {name: '交通运输设备制造业工程', twoList: ["甲级", "乙级"]},
                    {name: '交通运输设备制造业工程', twoList: ["甲级", "乙级"]}

                ]
            }, {
                name: '专业资质-商务粮行业', oneList: [
                    {name: '冷冻今藏工程', twoList: ["甲级", "乙级"]},
                    {name: '内食品加工工程', twoList: ["甲级", "乙级"]},
                    {name: '批发配送与物流仓储工程', twoList: ["甲级", "乙级"]},
                    {name: '成品油储运工程', twoList: ["甲级", "乙级"]},
                    {name: '粮食工程', twoList: ["甲级", "乙级"]},
                    {name: '油脂工程', twoList: ["甲级", "乙级"]}
                ]
            }, {
                name: '专业资质-煤炭行业', oneList: [
                    {name: '矿井', twoList: ["甲级", "乙级"]},
                    {name: '露天矿', twoList: ["甲级", "乙级"]},
                    {name: '选煤厂', twoList: ["甲级", "乙级"]}
                ]
            },
            {
                name: '专业资质-化工石化医药行业', oneList: [
                    {name: '炼油工程', twoList: ["甲级", "乙级"]},
                    {name: '化工工程', twoList: ["甲级", "乙级"]},
                    {name: '石油及化工产品储运', twoList: ["甲级", "乙级"]},
                    {name: '化工矿山', twoList: ["甲级", "乙级"]},
                    {name: '生化、生物药', twoList: ["甲级", "乙级"]},
                    {name: '化学原料药', twoList: ["甲级", "乙级"]},
                    {name: '中成药', twoList: ["甲级", "乙级"]},
                    {name: '药物制剂', twoList: ["甲级", "乙级"]}
                ]
            }, {
                name: '专业资质-石油天然气(海洋石油)行业', oneList: [
                    {name: '油田地面', twoList: ["甲级", "乙级"]},
                    {name: '气田地面', twoList: ["甲级", "乙级"]},
                    {name: '管道输送', twoList: ["甲级", "乙级"]},
                    {name: '海洋石油', twoList: ["甲级", "乙级"]},
                    {name: '油气库', twoList: ["甲级", "乙级"]},
                    {name: '油气加工', twoList: ["甲级", "乙级"]},
                    {name: '石油机械制造与修理', twoList: ["甲级", "乙级"]}
                ]
            }, {
                name: '专业资质-电力行业', oneList: [
                    {name: '水力发电(含抽水蓄能、潮汐)', twoList: ["甲级", "乙级"]},
                    {name: '新能源发电', twoList: ["甲级", "乙级"]},
                    {name: '变电工程', twoList: ["甲级", "乙级"]},
                    {name: '送电工程', twoList: ["甲级", "乙级"]},
                    {name: '风力发电', twoList: ["甲级", "乙级"]},
                    {name: '火力发电(含核电站常规岛设计)', twoList: ["甲级", "乙级"]}
                ]
            }, {
                name: '专业资质-冶全行业', oneList: [
                    {name: '全属台炼工程', twoList: ["甲级", "乙级"]},
                    {name: '全属材料工程', twoList: ["甲级", "乙级"]},
                    {name: '焦化和耐火材料工程', twoList: ["甲级", "乙级"]},
                    {name: '治金矿山工程', twoList: ["甲级", "乙级"]}
                ]
            }, {
                name: '专项资质', oneList: [
                    {name: '建筑昆装饰工程设计', twoList: ["甲级", "乙级"]},
                    {name: '环境工程-水污染防治', twoList: ["甲级", "乙级"]},
                    {name: '环境工程-大气污染防治', twoList: ["甲级", "乙级"]},
                    {name: '环境工程-固体废物处理', twoList: ["甲级", "乙级"]},
                    {name: '环境工程-物理污染防治', twoList: ["甲级", "乙级"]},
                    {name: '环境工程-污染修复工', twoList: ["甲级", "乙级"]},
                    {name: '消防设施工程设计', twoList: ["甲级", "乙级"]},
                    {name: '建筑智能化系统设计', twoList: ["甲级", "乙级"]},
                    {name: '建筑幕墙工程设计专项', twoList: ["甲级", "乙级"]},
                    {name: '轻型钢结构工程设计', twoList: ["甲级", "乙级"]},
                    {name: '照明工程设计专项', twoList: ["甲级", "乙级"]},
                    {name: '风景园林工程设计专项', twoList: ["甲级", "乙级"]}
                ]
            }, {
                name: '监理专业资质', oneList: [
                    {name: '房屋建筑工程', twoList: ["乙级"]},
                    {name: '冶炼工程', twoList: ["乙级"]},
                    {name: '矿山工程', twoList: ["乙级"]},
                    {name: '水利水电工程', twoList: ["乙级"]},
                    {name: '石油化工工程', twoList: ["乙级"]},
                    {name: '电力工程', twoList: ["乙级"]},
                    {name: '航天航空工程', twoList: ["乙级"]},
                    {name: '通信工程', twoList: ["乙级"]},
                    {name: '机电安装工程', twoList: ["乙级"]},
                    {name: '农林工程', twoList: ["乙级"]},
                    {name: '铁路工程', twoList: ["乙级"]},
                    {name: '市政公用工程', twoList: ["乙级"]},
                ]
            }, {
                name: '承装修试', oneList: [
                    {name: '承装修试', twoList: ["特级", "一级", "二级", "三级", "四级"]}
                ]
            }, {
                name: '房地产', oneList: [
                    {name: '房地产', twoList: ["特级", "一级", "二级", "三级", "四级"]}
                ]
            }
        ];
        //初始将省份数据赋予
        for (var i = 0; i < CretList.length; i++) {
            addEle(cert_serial, CretList[i].name);
        }

        //向select中 追加内容
        function addEle(ele, value) {
            var optionStr = "";
            optionStr = "<option value=" + value + " >" + value + "</option>";
            ele.append(optionStr);
        }

        //重新渲染select
        form.render('select');

        //移除select中所有项
        function removeEle(ele) {
            ele.find("option").remove();
            var optionStar = "<option value=''>" + "请选择" + "</option>";
            ele.append(optionStar);
        }

        var cert_serialText,
            cert_fromText,
            cert_fromItem;
        //选定省份后 将该省份的数据读取追加上
        form.on('select(cert_serial)', function (data) {
            var cert_from = $(data.elem).parents(".layui-form-item").find(".cert_from"),
                cert_level = $(data.elem).parents(".layui-form-item").find(".cert_level");
            cert_serialText = data.value;
            $.each(CretList, function (i, item) {
                if (cert_serialText == item.name) {
                    cert_fromItem = i;
                    return cert_fromItem;
                }
            });
            removeEle(cert_from);
            removeEle(cert_level);
            $.each(CretList[cert_fromItem].oneList, function (i, item) {
                addEle(cert_from, item.name);
            })
            form.render('select');
        })

        //选定后 将对应的数据读取追加上
        form.on('select(cert_from)', function (data) {
            var cert_level = $(data.elem).parents(".layui-form-item").find(".cert_level");
            cert_fromText = data.value;
            removeEle(cert_level);
            $.each(CretList, function (i, item) {
                if (cert_serialText == item.name) {
                    cert_fromItem = i;
                    return cert_fromItem;
                }
            });
            $.each(CretList[cert_fromItem].oneList, function (i, item) {
                if (cert_fromText == item.name) {
                    for (var n = 0; n < item.twoList.length; n++) {
                        addEle(cert_level, item.twoList[n]);
                    }
                }
            })
            form.render('select');
        })


    }

</script>
{/block}